import sys

sys.path.append('../..')
from common.config import *
from db.mysql import MysqlClient
from itertools import product
import requests, json
from pyquery import PyQuery as pq
from urllib.parse import urlencode
from common.helper import Helper
class Spider(object):
    def __init__(self):
        self.mysql = MysqlClient()
        self.name = "安享一生防癌险"
    # 生成产品数据
    def genProductInfo(self):
        data = {
            "product_type":"azyl_dianshang"
        }
        payload = urlencode( data )
        r = requests.post( url = domain[self.name]["url"],headers=domain[self.name]["header"],data=payload)
        if r.status_code == 200 and "成功" in r.text:

            items = r.json()["data"]["price_list"]
            for item in items:
                data = {
                    # 年龄段
                    "year":item[0],
                    # 保额
                    "money":"2000000",
                    #保障期限
                    "expire":"1年",
                    #交费类型
                    "payType":"年交",
                    #产品价格
                    "price":Helper.decimalParse( item[1] )
                }
                self.mysql.cursor.execute( domain[self.name]["insert_sql"].format( **data ))
                self.mysql._conn.commit()
                print( domain[self.name]["insert_sql"].format( **data ) )

